package web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import beans.Follow;
import beans.Likes;
import beans.Member;
import beans.TypeMessage;
import beans.Typer;
import service.FollowService;
import service.LikesService;
import service.TypeMessageService;
import service.TypeService;
import serviceimpl.FollowServiceIpmt;
import serviceimpl.LikesServiceIpmt;
import serviceimpl.MemberServiceIpmt;
import serviceimpl.TypeMessageServiceIpml;
import serviceimpl.TypeServiceIpmt;
@WebServlet("/ShowOthersMessage")
public class ShowOthersMessage extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		LikesService ls=new LikesServiceIpmt();
		FollowService fs = new FollowServiceIpmt();
		MemberServiceIpmt ipmt = new MemberServiceIpmt();
		String id = request.getParameter("id");
		Member member = ipmt.getMemberById(Integer.valueOf(id));
		HttpSession session = request.getSession();
		session.setAttribute("othermember", member);
		TypeService ts = new TypeServiceIpmt();
		Typer typer = ts.showType(member.getUsername());
		TypeMessageService tm = new TypeMessageServiceIpml();
		request.getSession().removeAttribute("typeMessageBytypes");
		if(typer!=null) {
			TypeMessage typeMessageBytype = tm.getTypeMessageBytype(typer.getType());
			request.getSession().setAttribute("typeMessageBytypes", typeMessageBytype);
		}
		Likes likes=new Likes();
		Follow follow = new Follow();
		Member member1 = (Member) session.getAttribute("member");
		likes.setUsername(member1.getUsername());
		likes.setLikeusername(member.getUsername());
		ls.likesStatus(likes);
		session.setAttribute("likasStatus", likes.getStatus());
		follow.setUsername(member1.getUsername());
		follow.setFollowusername(member.getUsername());
		fs.followStatus(follow);
		session.setAttribute("followStatus", follow.getStatus());
		response.sendRedirect("/zzLoveProduct/home/otherhome.jsp");
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}
